import {Component, ElementRef, OnInit} from '@angular/core';
import {ModalController} from "@ionic/angular";
import {Router} from "@angular/router";
import {HttpService} from "../../services/http/http.service";
import {MapLocationService} from "../../services/map-location.service";
import {API} from "../../services/API";

@Component({
  selector: 'app-select-province',
  templateUrl: './select-province.component.html',
  styleUrls: ['./select-province.component.scss'],
})
export class SelectProvinceComponent implements OnInit {
  flag = true;
  provincial = '';
  areas;
  pinYin;
  province; // 省
  list = [];
  cityList = [];
  area = '正在定位中...';
  adcode;
  cityCode = '';
  sourceLatitude = '';
  sourceLongitude = '';
  constructor(
      private modalController: ModalController,
      private router: Router,
      private httpService: HttpService,
      private ref: ElementRef,
      private mapLocation: MapLocationService,
  ) { }

  async ngOnInit() {
    const info = await this.httpService.post(API.COMMUNITY_PROVINCE, {}, false);
    console.log(info);
    if (info) {
      this.list = [];
      this.areas = Object.values(info);
      this.pinYin = Object.keys(info);
      console.log(this.areas);
      for (let i = 0; i< this.areas.length; i++){
        this.list.push({
          areas:this.areas[i],
          pinYin: this.pinYin[i]
        })
      }
    }
  }
  async onPageDidEnter() {

  }
  async selectArea(items) {
   console.log(items);
    const data = {
      id: items.id,
      name: items.name,
    }
    this.modalController.dismiss(data);
  }

  close() {
    console.log(111);
      this.modalController.dismiss();
  }
}
